package visao;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JButton;

import dao.DAOFactory;
import dao.MusicoDAO;

import modelo.Musico;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CadastraMusico extends JFrame {

	private JPanel contentPane;
	private JButton btnSalvar;
	private JButton btnCancelar;
	private JTextField txtNome;
	private JRadioButton rdbtnSim;
	private JRadioButton rdbtnNao;
	private JSeparator separator;

	private Musico musico = new Musico();

	private MusicoDAO dadosMusico = DAOFactory.getMusicoDAO();

	private boolean ehSolo;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadastraMusico frame = new CadastraMusico();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadastraMusico() {
		setTitle("CADASTRAR MUSICO");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 227);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(0, 0, 139));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblCadastrarMusico = new JLabel("Cadastrar Musico");
		lblCadastrarMusico.setBackground(new Color(250, 240, 230));
		lblCadastrarMusico.setForeground(new Color(0, 255, 255));
		lblCadastrarMusico.setFont(new Font("Comic Sans MS", Font.BOLD
				| Font.ITALIC, 18));
		lblCadastrarMusico.setHorizontalAlignment(SwingConstants.CENTER);
		lblCadastrarMusico.setBounds(10, 0, 422, 26);
		contentPane.add(lblCadastrarMusico);

		JLabel lblNome = new JLabel("Nome:");
		lblNome.setForeground(new Color(0, 255, 255));
		lblNome.setFont(new Font("Comic Sans MS", Font.PLAIN, 13));
		lblNome.setBounds(10, 37, 43, 14);
		contentPane.add(lblNome);

		txtNome = new JTextField();
		txtNome.setBounds(10, 60, 422, 20);
		contentPane.add(txtNome);
		txtNome.setColumns(10);

		JLabel lblSim = new JLabel("\u00C9 solo?");
		lblSim.setForeground(Color.CYAN);
		lblSim.setFont(new Font("Comic Sans MS", Font.PLAIN, 13));
		lblSim.setBounds(10, 91, 43, 14);
		contentPane.add(lblSim);

		rdbtnSim = new JRadioButton("Sim");
		rdbtnSim.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				if (rdbtnSim.isSelected()) {

					rdbtnSim.setSelected(true);

					rdbtnNao.setSelected(false);
					
					ehSolo = true;

				}

			}
		});
		rdbtnSim.setForeground(new Color(0, 255, 255));
		rdbtnSim.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
		rdbtnSim.setBackground(new Color(0, 0, 128));
		rdbtnSim.setBounds(10, 112, 61, 23);
		contentPane.add(rdbtnSim);

		rdbtnNao = new JRadioButton("N\u00E3o");
		rdbtnNao.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if (rdbtnNao.isSelected()) {

					rdbtnNao.setSelected(true);

					rdbtnSim.setSelected(false);
					
					ehSolo = false;

				}
			}
		});
		rdbtnNao.setForeground(Color.CYAN);
		rdbtnNao.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
		rdbtnNao.setBackground(new Color(0, 0, 128));
		rdbtnNao.setBounds(85, 114, 61, 23);
		contentPane.add(rdbtnNao);

		btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				musico.setNome(txtNome.getText());
				musico.setEhSolo(ehSolo);
				
				dadosMusico.salvar(musico);
			}
		});
		btnSalvar.setBackground(new Color(0, 255, 255));
		btnSalvar.setForeground(new Color(0, 0, 139));
		btnSalvar.setFont(new Font("Comic Sans MS", Font.BOLD, 11));
		btnSalvar.setBounds(10, 154, 91, 23);
		contentPane.add(btnSalvar);

		btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				txtNome.setText(null);
				rdbtnSim.setSelected(false);
				rdbtnNao.setSelected(false);

				dispose();
			}
		});
		btnCancelar.setForeground(new Color(0, 0, 139));
		btnCancelar.setFont(new Font("Comic Sans MS", Font.BOLD, 11));
		btnCancelar.setBackground(Color.CYAN);
		btnCancelar.setBounds(114, 154, 91, 23);
		contentPane.add(btnCancelar);

		separator = new JSeparator();
		separator.setBounds(10, 24, 422, 14);
		contentPane.add(separator);
	}
}
